package com.example.studentmanage.controller;

import com.example.studentmanage.dao.CourseDao;
import com.example.studentmanage.dao.StudentDao;
import com.example.studentmanage.pojo.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collection;

@Controller
public class CourseController {

    @Autowired
    CourseDao courseDao;

    @Autowired
    StudentDao studentDao;

    @RequestMapping("/hello/cou")
    public String helloStu(Model model){
        Collection<Course> courses=courseDao.getAllCourse();
        model.addAttribute("course",courses);
        return "course";
    }



    @RequestMapping("/upCou/{id}")
    public String upStudent(@PathVariable("id")Integer id,Model model){
        Course course=courseDao.getCourseByid(id);
        System.out.println(id);
        System.out.println(course);
        model.addAttribute("cou",course);
        return "updateC";
    }

    @PostMapping("/updateCou")
    public String update(Course course){
        courseDao.save(course);
        return "redirect:/hello/cou";
    }

}
